﻿#region 命名空间

using System.Text;
using WinnerCMS.Common;
using WinnerCMS.Common.Security;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// WinnerCMS 的 Cookie 类
    /// </summary>
    public static class WinnerCMSCookie
    {
        /// <summary>
        /// 生成识别码
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="psw"></param>
        /// <returns></returns>
        public static string MakeIdentifyCode(string userName, string psw)
        {
            StringBuilder sbToken = new StringBuilder();
            sbToken.Append(userName);
            sbToken.Append(System.Configuration.ConfigurationManager.AppSettings["IdentifyCode"]);
            sbToken.Append(psw);
            sbToken.Append(Key.HDVal());

            return Hash.Sha1(sbToken.ToString());
        }

        /// <summary>
        /// 检查识别码
        /// </summary>
        /// <param name="cookieString">被检查的识别码</param>
        /// <param name="userName">用户名</param>
        /// <param name="psw">权限</param>
        /// <returns></returns>
        public static bool CheckIdentyfyCode(string cookieString, string userName, string psw)
        {
            if (cookieString == MakeIdentifyCode(userName, psw))
            {
                return true;
            }
            return false;
        }
    }
}